#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 2e4 + 10, M = 1e5 + 10;

int n, m;
struct Seg{
    int a, b, c;

    bool operator< (Seg& w) const{
        return c > w.c;
    }
}seg[M];

int p[N];
int d[N];

int find(int x){
    if(x != p[x]){
        int t = find(p[x]);
        d[x] += d[p[x]];
        p[x] = t;
    }
    return p[x];
}

int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    cin >> n >> m;
    for(int i = 0; i < m; i ++){
        cin >> seg[i].a >> seg[i].b >> seg[i].c;
    }

    sort(seg, seg + m);

    for(int i = 1; i <= n; i ++) p[i] = i;

    for(int i = 0; i < m; i ++){
        int a = seg[i].a, b = seg[i].b, c = seg[i].c;
        int fa = find(a), fb = find(b);
        if(fa == fb && !((d[a] - d[b]) % 2)) {
            cout << c << '\n';
            exit(0);
        }

        if(fa != fb){
            p[fa] = fb;
            d[fa] = 1 + d[a] - d[b];
        }
    }

    cout << 0 << '\n';

    return 0;
}